package com.caocaog.market.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.service.MartResearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.caocaog.market.entity.MartResearch;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.Trim;
import org.jeecg.common.system.base.controller.GenericController;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * 市场调研
 *
 * @author chechen
 * @date 2022-01-13
 */
@Slf4j
@RestController
@Api(value = "martResearch", tags = MartResearchController.TABLE_MEANING)
@RequestMapping("/martResearch")
public class MartResearchController extends GenericController<MartResearch, MartResearchService> {

    public static final String TABLE_MEANING = "市场调研";

    @Trim
    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    @GetMapping
    @RequiresPermissions("martResearch:view")
    public Result<IPage<MartResearch>> queryPageList(MartResearch martResearch, QueryRequest queryRequest) {
        Page<MartResearch> page = PageGenerator.createPageSort(queryRequest);
        IPage<MartResearch> pageList = super.service.queryMartResearchPage(page, martResearch);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "根据id获取", notes = "根据id获取")
    @GetMapping("byId")
    @RequiresPermissions("martResearch:view")
    public Result<MartResearch> getMartResearchById(@RequestParam("id") String id) {
        return Result.OK(DELETE_SUCCESS, super.service.getMartResearchById(id));
    }

    @AutoLog(value = TABLE_MEANING + ADD)
    @ApiOperation(value = ADD, notes = ADD)
    @PostMapping
    @RequiresPermissions("martResearch:add")
    public Result<String> add(@RequestBody MartResearch martResearch) {
        return Result.OK(ADD_SUCCESS, super.service.addMartResearch(martResearch));
    }

    @AutoLog(value = TABLE_MEANING + EDIT)
    @ApiOperation(value = EDIT, notes = EDIT)
    @PutMapping
    @RequiresPermissions("martResearch:update")
    public Result<Integer> update(@RequestBody MartResearch martResearch) {
        return Result.OK(EDIT_SUCCESS, super.service.updateMartResearch(martResearch));
    }

    @AutoLog(value = TABLE_MEANING + DELETE)
    @ApiOperation(value = DELETE, notes = DELETE)
    @DeleteMapping
    @RequiresPermissions("martResearch:delete")
    public Result<Integer> delete(@RequestParam("id") Long id) {
        return Result.OK(DELETE_SUCCESS, super.service.deleteMartResearch(id));
    }

}
